package cn.stronglink.asset.module.resource.resourcegroup.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.ResourceGroup;
import cn.stronglink.asset.module.resource.resourcegroup.service.ResourceGroupService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value="resourceGroup")
public class ResourceGroupController extends AbstractController{
	@Autowired
	private ResourceGroupService resourceGroupService;
	/**
	 * 新增资源组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param borrowReturn
	 * @return
	 */
	@OperateLog(module = "资源组管理",desc="创建资源组", type = OpType.ADD)
	@RequestMapping(value="create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody ResourceGroup resourceGroup) {
		resourceGroupService.create(resourceGroup);
		return setSuccessModelMap(modelMap,null);
	}
	/**
	 * 编辑资源组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param resourceGroup
	 * @return
	 */
	@OperateLog(module = "资源组管理",desc="修改资源组", type = OpType.UPDATE)
	@RequestMapping(value="edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody ResourceGroup resourceGroup) {
		resourceGroupService.edit(resourceGroup);
		return setSuccessModelMap(modelMap,null);
	}
	/**
	 * 移除资源组
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param resourceGroup
	 * @return
	 */
	@OperateLog(module = "资源组管理",desc="删除资源组", type = OpType.DEL)
	@RequestMapping(value="remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		resourceGroupService.remove(id);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 查询资源组列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value="queryList")
	public ResponseEntity<ModelMap> queryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String,Object> params) {
		@SuppressWarnings("unchecked")
		Page<ResourceGroup> page = (Page<ResourceGroup>) super.getPage(params);
		Page<ResourceGroup> data = resourceGroupService.queryList(page,params);
		return setSuccessModelMap(modelMap,data);
	}
	/**
	 * 通过id查询
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value="qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		ResourceGroup data = resourceGroupService.qryById(id);
		return setSuccessModelMap(modelMap,data);
	}
	/**
	 * 查询所有资源组列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value="queryAllList")
	public ResponseEntity<ModelMap> queryAllList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {
		List<ResourceGroup> data = resourceGroupService.queryAllList();
		return setSuccessModelMap(modelMap,data);
	}
}
